package com.xiaoxin.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxin.lease.model.entity.LabelInfo;
import com.xiaoxin.lease.model.entity.RoomLabel;
import com.xiaoxin.lease.model.enums.ItemType;
import com.xiaoxin.lease.web.admin.mapper.LabelInfoMapper;
import com.xiaoxin.lease.web.admin.service.LabelInfoService;
import com.xiaoxin.lease.web.admin.service.RoomLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【label_info(标签信息表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class LabelInfoServiceImpl extends ServiceImpl<LabelInfoMapper, LabelInfo>
    implements LabelInfoService{

    @Autowired
    private LabelInfoMapper labelInfoMapper;

    @Autowired
    RoomLabelService roomLabelService;;

    @Override
    public List<LabelInfo> selectByItemType(int id) {
        return labelInfoMapper.selectByItemType(id);
    }

    @Override
    public int addLabelInfo(LabelInfo labelInfo) {
        return labelInfoMapper.addLabelInfo(labelInfo);
    }

    @Override
    public int updateLabelInfo(LabelInfo labelInfo) {
        return labelInfoMapper.updateLabelInfo(labelInfo);
    }

    @Override
    public List<LabelInfo> getAllLabelInfo(Long id) {
        List<LabelInfo> labelInfoList = new ArrayList<>();
       List<RoomLabel> roomLabelList =  roomLabelService.list(new LambdaQueryWrapper<RoomLabel>().eq(RoomLabel::getRoomId,id));
       if(roomLabelList.size()>0){
           labelInfoList =  super.list(new LambdaQueryWrapper<LabelInfo>().eq(LabelInfo::getType, ItemType.ROOM).in(LabelInfo::getId,roomLabelList.stream().map(f -> f.getLabelId()).toList()));

       }
        return labelInfoList;
    }
}




